<template lang="pug">
	.get-with-certificate-wrap
		.top-tip
			top-tip( tip="请填写新生儿父亲或母亲的姓名、身份证信息")
		.card-input-container
			input-line(leftText='父(母)姓名' placeholder="请输入父亲或母亲的姓名" type="text" @getValue="getParentName")
			input-line(leftText='身份证号' placeholder="请输入对应的身份证号码" type="idcard" @getValue="getIdNumber" maxlength="18" :showBorder="false")
		.card-btn(@click="jumpToNext")
			main-button(text="下一步" :isActive="nextStepPass")
</template>

<script>
import inputLine from '@/components/input-line'
import mainButton from '@/components/main-button'
import topTip from '@/components/top-tip'
export default {
	name: 'getWithoutCertificate',
	data() {
		return {
			parentName: '',
			idNumber: '',
			nextStepPassParentName: false,
			nextStepPassIdNumber: false
		}
	},
	computed: {
		nextStepPass() {
			return this.nextStepPassParentName && this.nextStepPassIdNumber
		}
	},
	created() {},
	mounted() {},
	methods: {
		jumpToNext() {
			if (this.nextStepPass) {
				this.submit()
			}
		},
		getParentName(text) {
			text = text.toString()
			this.parentName = text
			this.nextStepPassParentName = text.length > 0
		},
		getIdNumber(text) {
			text = text.toString()
			this.idNumber = text
			if (text.length === 15 || text.length === 18) {
				this.nextStepPassIdNumber = this.tools.identityCodeValid(text)
			} else {
				this.nextStepPassIdNumber = false
			}
		},
		submit() {
			this.wx.showLoading({
				title: '加载中'
			})
			this.api.childrenApi
				.getChildList({
					motherCardId: '350182199009025126',
					motherName: '柯玲玲'
				})
				.then(data => {
					if (data) {
						this.wx.setStorage({
							key: 'babyInfo',
							data: data
						})
						this.$router.push({
							path: '/views/healthCard/confirmBirthInfo'
						})
					} else {
						this.wx.showToast({
							title: '无法查询到相关的新生儿信息，请您检查输入的信息是否正确',
							icon: 'none'
						})
					}
					this.wx.hideLoading()
				})
				.catch(() => {
					this.wx.hideLoading()
				})
		}
	},
	components: {
		topTip,
		inputLine,
		mainButton
	}
}
</script>

<style lang="stylus">
	.get-with-certificate-wrap
		.top-tip
			padding mainPadding
		.card-input-container
			margin-bottom mainMargin
			background-color white
			.input-line-wrap
				margin 0
				padding 0 40px
		.card-btn
			width 690px
			height 92px
			margin 60px auto 0
			border-radius 46px
			overflow hidden
</style>
